/* 设备签到 */
const _ = require('lodash');
exports.run = (info, core, socket, logger) => {
  const Charging = core.getModel('Charging');
  const reader = new core.BufferReader(info.data),
    charging = reader.read(8),
    chargingCode = reader.read(20),
    softVersion = reader.read(4),
    startTimes = reader.read(4),
    storageSpace = reader.read(4),
    runTime = reader.read(4),
    lastStartTime = reader.read(8),
    lastSignTime = reader.read(8);
  console.log('充电桩编码', charging.toString('hex'));
  // console.log('系统设备资产编码', chargingCode);
  // console.log('系统设备资产编码', chargingCode.toString('ascii'));
  // console.log('系统软件版本', softVersion);
  // console.log('启动次数', startTimes);
  // console.log('启动次数', startTimes.readUInt32LE());
  // console.log('存储空间容量', storageSpace);
  // console.log('存储空间容量', storageSpace.readUInt32LE());
  // console.log('运行时间', runTime);
  // console.log('运行时间', runTime.readUInt32LE());
  // console.log('最近一次启动时间', lastStartTiem);
  // console.log('最近一次签到时间', lastSignTiem);
  socket.charging = charging.toString('hex').replace(/^0+/, '');
  Charging.access(socket.charging)
    .then(() => {
      // 发送 0x09 中心系统答复签到命令
      const userIdBuf = core.createIntBuffer(2, 2);
      const cmdIndexBuf = core.createIntBuffer(1, 2);
      socket.sendCommands(0x09, core.concat([userIdBuf, cmdIndexBuf, charging]));
      // 同步时间
      socket.sendCommands(0x42, core.concat([userIdBuf, cmdIndexBuf, core.date.date2Buffer(new Date())]));
    });
};
